package com.example.demo.controller;

import com.example.demo.model.User4;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

/**
 * swagger示例
 * swagger UI地址：http://localhost:8081/swagger-ui.html
 * swagger API地址：http://localhost:8081/v3/api-docs
 * v3 Tag注解对应的是v2 Swagger的Tag 用于分组
 * v3 Operation注解对应的是v2 Swagger的ApiOperation 用于接口信息描述
 * v3 Schema注解对应的是v2 Swagger的ApiModel 用于实体类描述
 * v3 Parameter注解对应的是v2 Swagger的ApiParam 用于路径参数、查询参数描述
 */
@Tag(name = "Swagger示例")
@RestController
@RequestMapping("/swagger")
public class SwaggerController {

    @Operation(summary = "查询用户信息", operationId = "getUser")
    @PostMapping("/getUser")
    public User4 getUser() {
        return User4.builder().id(123L).name("张三").age(20).build();
    }

    @Operation(summary = "新增用户信息", operationId = "addUser")
    @PostMapping("/addUser")
    public User4 addUser(User4 user) {
        return user;
    }

    @Operation(summary = "更新用户信息", operationId = "updateUser")
    @PostMapping("/updateUser")
    public User4 updateUser(User4 user) {
        return user;
    }

    @Operation(summary = "删除用户信息", operationId = "deleteUser")
    @PostMapping("/deleteUser/{id}")
    public void deleteUser(@Parameter(description = "用户ID", required = true) @PathVariable Long id) {
        System.out.println("删除用户信息，id：" + id);
    }

    @Operation(summary = "查询用户信息", operationId = "queryUser")
    @GetMapping("/queryUser")
    public User4 queryUser(
            @Parameter(description = "用户ID", required = true) @RequestParam Long id,
            @Parameter(description = "用户名称", required = true) @RequestParam String name
    ) {
        return User4.builder().id(id).name(name).age(20).build();
    }
}
